import React, { forwardRef, useRef } from 'react'

const MyInput = forwardRef((props, ref) => {
  return <div>子：<input ref={ref} type="text" /></div>
})

export default function ForwardRefDemo() {
  const inputRef = useRef();
  
  return (
    <div>
      父：<button onClick={e => inputRef.current.focus()}>聚焦</button>
      <MyInput ref={inputRef}/>
    </div>
  )
}
